import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:ost_flutter_module/common/adapt.dart';
import 'package:ost_flutter_module/common/color.dart';
import 'package:ost_flutter_module/common/styles.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_textfiled.dart';
import 'package:ost_flutter_module/widget/custom_widget/text_button.dart';

class StoreCourseServiceConsultPage extends StatelessWidget {
  const StoreCourseServiceConsultPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: true,
      appBar: appBar(context),
      body: body(context),
      bottomNavigationBar: bottomNavigationBar(context),
    );
  }

  Widget appBar(BuildContext context) {
    return
        // PreferredSize(
        //   preferredSize: Size.fromHeight(90),
        //   child:
        AppBar(
      elevation: 0,
      iconTheme: IconThemeData(color: Colors.white),
      backgroundColor: colorA1D0FF,
      leadingWidth: Adapt.px(20),
      title: Container(
        height: 60,
        child: Stack(
          clipBehavior: Clip.none,
          fit: StackFit.expand,
          children: [
            Container(
              child: SvgPicture.asset(
                'assets/images/sc_nav.svg',
                fit: BoxFit.fitWidth,
              ),
            ),
            Center(
              child: Text('服务咨询', style: TextStyles.appBarWhiteTitleStyle),
            ),
          ],
        ),
      ),
      // ),
    );
  }

  Widget body(BuildContext context) {
    return GestureDetector(
      onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
      child: Container(
        width: double.infinity,
        height: double.infinity,
        color: colorA1D0FF,
        child: Padding(
          padding: EdgeInsets.only(
              left: Adapt.px(8), right: Adapt.px(8), bottom: Adapt.px(8)),
          child: Stack(
            clipBehavior: Clip.none,
            fit: StackFit.expand,
            children: [
              Container(
                child: SvgPicture.asset(
                  'assets/images/sc_body.svg',
                  fit: BoxFit.fill,
                ),
              ),
              _bodyContainer(context),
            ],
          ),
        ),
      ),
    );
  }

  Widget _bodyContainer(BuildContext context) {
    final List _list = ['孩子姓名', '孩子生日', '联系手机', '所在地区'];

    return SingleChildScrollView(
      child: Padding(
        padding: EdgeInsets.only(
          top: Adapt.px(60),
          left: Adapt.px(20),
          right: Adapt.px(20),
          bottom: Adapt.px(20),
        ),
        child: Column(
          children: [
            Center(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                textBaseline: TextBaseline.ideographic,
                children: [
                  Text(
                    '联系课程老师获得更详细的课程推荐咨询',
                    style: TextStyle(fontSize: 16, color: color42270C),
                  ),
                  SizedBox(height: Adapt.px(10)),
                  Text(
                    '请留下您的信息以及想要咨询的问题，我们的课程老师会在2天内与您联系',
                    style: TextStyle(fontSize: 12, color: color999999),
                    maxLines: 2,
                  ),
                ],
              ),
            ),
            SizedBox(height: Adapt.px(20)),
            ListView.builder(
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemCount: _list.length,
              itemBuilder: (context, index) {
                return _bodyTextFiled(
                  context,
                  text: _list[index],
                  isNess: index == 2 || index == 3,
                  isTextField: index != 1,
                  hintText: index != 1 ? '请输入' : '请选择',
                );
              },
            ),
            SizedBox(height: Adapt.px(30)),
            other(context),
          ],
        ),
      ),
    );
  }

  Widget _bodyTextFiled(BuildContext context,
      {String text, bool isNess, bool isTextField, String hintText}) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: Adapt.px(10)),
      child: IntrinsicHeight(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(text ?? '', style: TextStyles.titleStyle),
            isNess
                ? Text('*', style: TextStyle(color: colorFF5454, fontSize: 16))
                : Container(width: 6),
            SizedBox(width: Adapt.px(20)),
            Expanded(
              child: Container(
                height: Adapt.px(40),
                decoration: BoxDecoration(
                  shape: BoxShape.rectangle,
                  border: Border.all(color: colorFFCDCED2),
                  borderRadius: BorderRadius.circular(Adapt.px(20)),
                ),
                child: input(context,
                    isTextField: isTextField, hintText: hintText),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget input(BuildContext context, {bool isTextField, String hintText}) {
    return isTextField
        ? Row(
            children: [
              Container(width: 10),
              Expanded(
                child: GTextField(
                  hintText: hintText,
                  maxLine: 1,
                  textFieldCenter: true,
                ),
              ),
            ],
          )
        : GTextButton(
            child: Align(
              alignment: Alignment.centerLeft,
              child: Text(
                hintText ?? '',
                style: TextStyles.hintTitleStyle,
              ),
            ),
            isStadiumBorder: true,
            onPressed: () {
              var _dateTime = DateTime.now();
              CupertinoDatePicker(
                initialDateTime: _dateTime,
                mode: CupertinoDatePickerMode.date,
                onDateTimeChanged: (date) {},
              );
            },
          );
  }

  Widget other(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('咨询问题', style: TextStyles.titleStyle),
        SizedBox(height: Adapt.px(10)),
        Container(
          height: Adapt.px(88),
          child: Container(
            decoration: BoxDecoration(
              shape: BoxShape.rectangle,
              border: Border.all(color: colorFFCDCED2),
              borderRadius: BorderRadius.circular(Adapt.px(20)),
            ),
            child: Padding(
              padding: EdgeInsets.all(Adapt.px(10)),
              child: GTextField(
                hintText: '请输入',
              ),
            ),
          ),
        ),
      ],
    );
  }

  // Widget customAppbar(BuildContext context) {
  //   return Container(
  //     color: Colors.red,
  //     height: Adapt.px(80),
  //     child: Row(
  //       crossAxisAlignment: CrossAxisAlignment.center,
  //       children: [
  //         Container(
  //           width: Adapt.px(20),
  //           child: BackButton(color: Colors.white),
  //         ),
  //         Container(
  //           // width: double.infinity,
  //           color: Colors.blueAccent,
  //           child: SvgPicture.asset(
  //             'assets/images/sc_nav.svg',
  //             fit: BoxFit.fill,
  //           ),
  //         ),
  //       ],
  //     ),
  //   );
  // }

  Widget bottomNavigationBar(BuildContext context) {
    double width = Adapt.getScreenWidth / 2, height = Adapt.px(60);
    return SafeArea(
      bottom: true,
      child: Container(
        color: Colors.red,
        width: double.infinity,
        child: ButtonBar(
          buttonPadding: EdgeInsets.all(0),
          children: [
            Container(
              width: width,
              height: height,
              child: GTextButton(
                title: '取消',
                normalBackgroundColor: Colors.white,
                normalForgroundColor: color666666,
                onPressed: () => Navigator.pop(context),
              ),
            ),
            Container(
              width: width,
              height: height,
              child: GTextButton(
                title: '提交',
                normalBackgroundColor: colorFACD33,
                normalForgroundColor: color42270C,
                onPressed: () {},
              ),
            ),
          ],
        ),
      ),
    );
  }
}
